package main

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func main() {
	engine := gin.Default()
	engine.GET("/student/get", GetStudent)
	engine.GET("/student/getbyparam", GetStudentByParam)
	engine.GET("/student/defaultquery", DefaultQuery)
	engine.Run()
}

func DefaultQuery(c *gin.Context) {
	stuNo := c.DefaultQuery("stuNo", "123456")
	log.Printf("stuNo=%s", stuNo)
	c.String(http.StatusOK, "stuNo=%s", stuNo)
}

func GetStudentByParam(c *gin.Context) {
	var param StudentParam
	if c.ShouldBindQuery(&param) == nil {
		log.Printf("stuNo=%s, delted=%d", param.StuNo, param.Deleted)
		c.JSON(http.StatusOK, &param)
	}
}

type StudentParam struct {
	StuNo string `form:"stuNo"`
	Deleted int `form:"deleted"`
}

func GetStudent(c *gin.Context) {
	id := c.Query("id")
	c.JSON(http.StatusOK, gin.H{"id": id})
}
